package channel;

import core.AnalogSignal;

/**
 * Created by Eugene Khoroshutin
 * Date: 2/4/13
 * Time: 11:42 PM
 */
public class PropagatorSignal implements AnalogSignal {
    public double frequency;
    public double amplitude;
    public double phase;
    public double xStart, xEnd;

    public double dStart0, dEnd0;
    public double dAmplitude0, dAmplitude1, dFrequency0, dFrequency1, dPhase0, dPhase1;

    public PropagatorSignal(double _frequency, double _amplitude, double _phase, double _start, double _end) {
        frequency = _frequency;
        amplitude = _amplitude;
        phase = _phase;
        xStart = _start;
        xEnd = _end;
    }

    public PropagatorSignal(double xStart, double xEnd) {
        this.xStart = xStart;
        this.xEnd = xEnd;
    }

    /**
     * Returns f(x) for current signal
     *
     * @param _x time variable, s
     * @return real value of signal function in x point
     */
    @Override
    public double function(double _x) {
        if (dEnd0 != 0) {
            if (dStart0 <= _x && _x <= dEnd0) {
                return dAmplitude0 * Math.sin(2 * Math.PI * dFrequency0 * _x + dPhase0);
            } else {
                return dAmplitude1 * Math.sin(2 * Math.PI * dFrequency1 * _x + dPhase1);
            }
        } else {
            return amplitude * Math.sin(2 * Math.PI * frequency * _x + phase);
        }
    }

    /**
     * Returns signal frequency, Hz
     *
     * @return real value of signal frequency
     */
    @Override
    public double getFrequency() {
        if (dEnd0 != 0) {
            throw new UnsupportedOperationException("Not supported anymore.");
        } else {
            return frequency;  //To change body of implemented methods use File | Settings | File Templates.
        }
    }

    @Override
    public double getAmplitude() {
        if (dEnd0 != 0) {
            throw new UnsupportedOperationException("Not supported anymore.");
        } else {
            return amplitude;  //To change body of implemented methods use File | Settings | File Templates.
        }
    }

    @Override
    public double getPhase() {
        if (dEnd0 != 0) {
            throw new UnsupportedOperationException("Not supported anymore.");
        } else {
            return phase;  //To change body of implemented methods use File | Settings | File Templates.
        }
    }

    @Override
    public double getStart() {
        return xStart;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public double getEnd() {
        return xEnd;  //To change body of implemented methods use File | Settings | File Templates.
    }

    public void setdStart0(double dStart0) {
        this.dStart0 = dStart0;
    }

    public void setdEnd1(double dEnd0) {
        this.dEnd0 = dEnd0;
    }

    public void setdAmplitude0(double dAmplitude0) {
        this.dAmplitude0 = dAmplitude0;
    }

    public void setdAmplitude1(double dAmplitude1) {
        this.dAmplitude1 = dAmplitude1;
    }

    public void setdFrequency0(double dFrequency0) {
        this.dFrequency0 = dFrequency0;
    }

    public void setdFrequency1(double dFrequency1) {
        this.dFrequency1 = dFrequency1;
    }

    public void setdPhase0(double dPhase0) {
        this.dPhase0 = dPhase0;
    }

    public void setdPhase1(double dPhase1) {
        this.dPhase1 = dPhase1;
    }
}
